package com.sybil.spa.controlador;

import org.hibernate.exception.ConstraintViolationException;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;

@ControllerAdvice
class GlobalDefaultExceptionHandler {
//
//   public static final String DEFAULT_ERROR_VIEW = "usuario/error";
//
//   @ExceptionHandler(DataIntegrityViolationException.class)
//   public ModelAndView handleConflict(DataIntegrityViolationException e) {
//      ModelAndView mav = new ModelAndView(DEFAULT_ERROR_VIEW);
//      mav.addObject("usuario", "No se puede eliminar el registro ya que otros depende de este.");
//      mav.addObject("name", e.getClass().getSimpleName());
//      mav.addObject("message", e.getMessage());
//      return mav;
//   }
//
//   @ExceptionHandler(ConstraintViolationException.class)
//   public ModelAndView handleConflict(ConstraintViolationException e) {
//      ModelAndView mav = new ModelAndView(DEFAULT_ERROR_VIEW);
//      mav.addObject("usuario", "Ya existe un registro con esta clave o id, favor de utilizar una diferente.");
//      mav.addObject("name", e.getClass().getSimpleName());
//      mav.addObject("message", e.getMessage());
//      return mav;
//   }
////   @ExceptionHandler(value = Exception.class)
////   public ModelAndView defaultErrorHandler(HttpServletRequest req, Exception e) throws Exception {
////      if (AnnotationUtils.findAnnotation(e.getClass(), ResponseStatus.class) != null) {
////         throw e;
////      }
////
////      ModelAndView mav = new ModelAndView();
////      mav.addObject("exception", e);
////      mav.addObject("url", req.getRequestURL());
////      mav.setViewName(DEFAULT_ERROR_VIEW);
////      return mav;
////   }
//
//   @ExceptionHandler(Exception.class)
//   public ModelAndView exception(Exception e) {
//      ModelAndView mav = new ModelAndView(DEFAULT_ERROR_VIEW);
//      mav.addObject("name", e.getClass().getSimpleName());
//      mav.addObject("message", e.getMessage());
//      return mav;
//   }
}
